﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


using System.Drawing;
using System.Windows.Shapes;



namespace HA.Data.DisplayOptions2
{
    /// <summary>
    /// 对应modflow选项卡
    /// </summary>
    [Serializable]
    public class DOModFlow :  EventProperty,IObjectDataHelper, ICloneable
    {

        #region 构造函数

        public DOModFlow()
        {

            this._wells = new DOEntity(Color.Gold, DisplayShape.Diamond);//
            this._drains = new DOEntity(Color.Blue, DisplayShape.Diamond);//
            this._rivers = new DOEntity(Color.Blue, DisplayShape.TriangleUp);//
            this._constantHead = new DOEntity(Color.Black, DisplayShape.Diamond);//
            this._generalHead = new DOEntity(Color.Green, DisplayShape.TriangleUp);//
            this._transientData = new DOEntity(Color.Purple, DisplayShape.Diamond);//

            this._dryCell = new DOEntity(Color.Red, DisplayShape.Circle);
            this._markFloodedCell = new DOEntity(Color.Blue, DisplayShape.Square);

            this._waterTable = new DOEntity(Color.Blue, DisplayShape.Line);
            this._horizFlowBarrier = new DOEntity(Color.Sienna, DisplayShape.Line);//
        }


        #endregion






        DOEntity _wells;

        public DOEntity Wells
        {
            get { return _wells; }
            set
            {
                if (_wells == value)
                {
                    return;
                }
                else
                {
                    _wells = value;
                    this.IsNeedUpdateData = true;
                }
            }
        }

        DOEntity _rivers;

        public DOEntity Rivers
        {
            get { return _rivers; }
            set
            {
                if (_rivers == value)
                {
                    return;
                }
                else
                {
                    _rivers = value;
                    this.IsNeedUpdateData = true;
                }
            }
        }

        DOEntity _drains;

        public DOEntity Drains
        {
            get { return _drains; }
            set
            {
                if (_drains == value)
                {
                    return;
                }
                else
                {
                    _drains = value;
                    this.IsNeedUpdateData = true;
                }
            }
        }

        DOEntity _generalHead;

        public DOEntity GeneralHead
        {
            get { return _generalHead; }
            set
            {
                if (_generalHead == value)
                {
                    return;
                }
                else
                {
                    _generalHead = value;
                    this.IsNeedUpdateData = true;
                }
            }
        }

        DOEntity _constantHead;

        public DOEntity ConstantHead
        {
            get { return _constantHead; }
            set
            {
                if (_constantHead == value)
                {
                    return;
                }
                else
                {
                    _constantHead = value;
                    this.IsNeedUpdateData = true;
                }
            }
        }

        DOEntity _transientData;

        public DOEntity TransientData
        {
            get { return _transientData; }
            set
            {
                if (_transientData == value)
                {
                    return;
                }
                else
                {
                    _transientData = value;
                    this.IsNeedUpdateData = true;
                }
            }
        }

        DOEntity _horizFlowBarrier;

        public DOEntity HorizFlowBarrier
        {
            get { return _horizFlowBarrier; }
            set
            {
                if (_horizFlowBarrier == value)
                {
                    return;
                }
                else
                {
                    _horizFlowBarrier = value;
                    this.IsNeedUpdateData = true;
                }
            }
        }

        DOEntity _dryCell;

        public DOEntity DryCell
        {
            get { return _dryCell; }
            set
            {
                if (_dryCell == value)
                {
                    return;
                }
                else
                {
                    _dryCell = value;
                    this.IsNeedUpdateData = true;
                }
            }
        }

        DOEntity _waterTable;

        public DOEntity WaterTable
        {
            get { return _waterTable; }
            set
            {
                if (_waterTable == value)
                {
                    return;
                }
                else
                {
                    _waterTable = value;
                    this.IsNeedUpdateData = true;
                }
            }
        }

        DOEntity _markFloodedCell;

        public DOEntity MarkFloodedCell
        {
            get { return _markFloodedCell; }
            set
            {
                if (_markFloodedCell == value)
                {
                    return;
                }
                else
                {
                    _markFloodedCell = value;
                    this.IsNeedUpdateData = true;
                }
            }
        }



   


        /// <summary>
        /// 绘制指定的图形
        /// </summary>
        /// <param name="size"></param>
        /// <param name="color"></param>
        /// <param name="display"></param>
        /// <returns></returns>
        public object GetStyle(int size, System.Windows.Media.Color color, DisplayShape display)
        {
            if (display == DisplayShape.Circle)
            {
                Ellipse ell = new Ellipse();
                ell.Fill = new System.Windows.Media.SolidColorBrush(color);
                ell.Width = size;
                ell.Height = size;
                return ell;
            }
            if (display == DisplayShape.Square)
            {
                System.Windows.Shapes.Rectangle rec = new System.Windows.Shapes.Rectangle();
                rec.Fill = new System.Windows.Media.SolidColorBrush(color);
                rec.Width = size;
                rec.Height = size;
                return rec;
            }
            if (display == DisplayShape.Diamond)
            {
                System.Windows.Shapes.Rectangle rec = new System.Windows.Shapes.Rectangle();
                rec.Fill = new System.Windows.Media.SolidColorBrush(color);
                rec.Width = size;
                rec.Height = size;
                rec.RenderTransform = new System.Windows.Media.RotateTransform(45, size / 2, size / 2);
                return rec;
            }

            if (display == DisplayShape.TriangleUp)
            {

                Polygon pol = new Polygon();
                pol.Fill = new System.Windows.Media.SolidColorBrush(color);
                pol.Width = size;
                pol.Height = size;
                List<System.Windows.Point> arry = new List<System.Windows.Point>();
                arry.Add(new System.Windows.Point(size, 0));
                arry.Add(new System.Windows.Point(size / 2, size));
                arry.Add(new System.Windows.Point(0, 0));
                pol.Points = new System.Windows.Media.PointCollection(arry);
                pol.RenderTransform = new System.Windows.Media.RotateTransform(180, size / 2, size / 2);
                return pol;
            }

            //if (display == DisplayShape.Cross)
            //{
            //    Canvas canvas = new Canvas();
            //    canvas.Width = size;
            //    canvas.Height = size;
            //    Path path = new Path();
            //    System.Windows.Media.GeometryConverter gc = new System.Windows.Media.GeometryConverter();
            //    //"M0,0 L14,0"
            //    string str = "M0,0 L" + size + ",0";

            //    path.Data = (System.Windows.Media.Geometry)gc.ConvertFromString(str);
            //    path.Margin = new Thickness(0, size / 2, 0, 0);
            //    path.Stroke = new System.Windows.Media.SolidColorBrush(color);
            //    path.StrokeThickness = 2;
            //    canvas.Children.Add(path);

            //    path = new Path();
            //    gc = new System.Windows.Media.GeometryConverter();
            //    str = "M0,0 L0," + size;
            //    path.Data = (System.Windows.Media.Geometry)gc.ConvertFromString(str);
            //    path.Margin = new Thickness(size / 2, 0, 0, 0);
            //    path.Stroke = new System.Windows.Media.SolidColorBrush(color);
            //    path.StrokeThickness = 2;
            //    canvas.Children.Add(path);
            //    return canvas;
            //}
            //if (display == DisplayShape.CircleNoFill)
            //{
            //    Ellipse ell = new Ellipse();
            //    ell.Stroke = new System.Windows.Media.SolidColorBrush(color);
            //    ell.StrokeThickness = 2;
            //    ell.Width = size;
            //    ell.Height = size;
            //    return ell;
            //}

            //if (display == DisplayShape.SquareNoFill)
            //{
            //    System.Windows.Shapes.Rectangle rec = new System.Windows.Shapes.Rectangle();
            //    rec.Stroke = new System.Windows.Media.SolidColorBrush(color);
            //    rec.StrokeThickness = 2;
            //    rec.Width = size;
            //    rec.Height = size;
            //    return rec;
            //}

            //if (display == DisplayShape.DiamondNoFill)
            //{
            //    System.Windows.Shapes.Rectangle rec = new System.Windows.Shapes.Rectangle();
            //    rec.StrokeThickness = 2;
            //    rec.Stroke = new System.Windows.Media.SolidColorBrush(color);
            //    rec.Width = size;
            //    rec.Height = size;
            //    rec.RenderTransform = new System.Windows.Media.RotateTransform(45, size / 2, size / 2);
            //    return rec;
            //}

            //if (display == DisplayShape.TriangleNoFill)
            //{
            //    Polygon pol = new Polygon();
            //    pol.Stroke = new System.Windows.Media.SolidColorBrush(color);
            //    pol.StrokeThickness = 2;
            //    pol.Width = size;
            //    pol.Height = size;
            //    List<System.Windows.Point> arry = new List<System.Windows.Point>();
            //    arry.Add(new System.Windows.Point(size, 0));
            //    arry.Add(new System.Windows.Point(size / 2, size));
            //    arry.Add(new System.Windows.Point(0, 0));
            //    pol.Points = new System.Windows.Media.PointCollection(arry);
            //    pol.RenderTransform = new System.Windows.Media.RotateTransform(180, size / 2, size / 2);
            //    return pol;
            //}
            //if (display == DisplayShape.SlashCross)
            //{
            //    Canvas canvas = new Canvas();
            //    canvas.Width = size;
            //    canvas.Height = size;
            //    Path path = new Path();
            //    System.Windows.Media.GeometryConverter gc = new System.Windows.Media.GeometryConverter();
            //    //"M0,0 L14,0"
            //    string str = "M" + size + ",0" + " L0," + size;

            //    path.Data = (System.Windows.Media.Geometry)gc.ConvertFromString(str);
            //    //path.Margin = new Thickness(0, size / 2, 0, 0);
            //    path.Stroke = new System.Windows.Media.SolidColorBrush(color);
            //    path.StrokeThickness = 2;
            //    canvas.Children.Add(path);

            //    path = new Path();
            //    gc = new System.Windows.Media.GeometryConverter();
            //    str = "M" + size * 2 + "," + size + " L" + size + ",0";
            //    path.Data = (System.Windows.Media.Geometry)gc.ConvertFromString(str);
            //    path.Margin = new Thickness(-size, 0, 0, 0);

            //    path.Stroke = new System.Windows.Media.SolidColorBrush(color);
            //    path.StrokeThickness = 2;
            //    canvas.Children.Add(path);
            //    return canvas;
            //}
            if (display == DisplayShape.DottedLine)
            {

                Line line = new Line();
                line.X1 = 0;
                line.X2 = 14;
                line.Y1 = 0;
                line.Y2 = 0;
                line.Stroke = new System.Windows.Media.SolidColorBrush(color);
                System.Windows.Media.DoubleCollection doub = new System.Windows.Media.DoubleCollection();
                doub.Add(2);
                doub.Add(1);
                line.StrokeDashArray = doub;
                line.StrokeThickness = size;
                return line;
            }
            if (display == DisplayShape.Line)
            {

                Line line = new Line();
                line.X1 = 0;
                line.X2 = 20;
                line.Y1 = 0;
                line.Y2 = 0;

                line.Stroke = new System.Windows.Media.SolidColorBrush(color);
                line.StrokeThickness = size;
                return line;
            }
            return null;
        }





        public object Clone()
        {
            DOModFlow obj = new DOModFlow();
            //obj = (DOModFlow)this.MemberwiseClone();


            obj._isShowTab = this._isShowTab;
            obj.isNeedUpdateData = this.isNeedUpdateData;


            obj.ConstantHead = (DOEntity)this.ConstantHead.Clone();


            //obj.Drains = new DOEntity( new Color (),DisplayShape.Circle);
            obj.Drains = (DOEntity)this.Drains.Clone();
            obj.DryCell = (DOEntity)this.DryCell.Clone();
            obj.GeneralHead = (DOEntity)this.GeneralHead.Clone();
            obj.HorizFlowBarrier = (DOEntity)this.HorizFlowBarrier.Clone();
            obj.MarkFloodedCell = (DOEntity)this.MarkFloodedCell.Clone();
            obj.Rivers = (DOEntity)this.Rivers.Clone();
            obj.TransientData = (DOEntity)this.TransientData.Clone();
            obj.WaterTable = (DOEntity)this.WaterTable.Clone();
            obj.Wells = (DOEntity)this.Wells.Clone();
            return obj;
        }
       



        #region IObjectDataHelper 成员

        /// <summary>
        /// 更新副本数据到原始数据数据   判断对应的选项改变，并作出对应的更新动作
        /// </summary>
        /// <param name="obj"></param>
        public void ResetDataAndTriggerEvent(object obj)
        {
            if (obj == null)
            {
                return;
            }


            DOModFlow nModflow = (DOModFlow)obj;

            if (nModflow.IsDataChanged() == false)
            {
                return;
            }
            try
            {


                List<string> props = new List<string>();

                if (this._markFloodedCell != nModflow.MarkFloodedCell)
                {
                    this._markFloodedCell = nModflow.MarkFloodedCell;
                    props.Add(DOModFlowType.MarkFloodedCell.ToString());
                }
                if (this._constantHead != nModflow.ConstantHead)
                {
                    this._constantHead = nModflow.ConstantHead;
                    props.Add(DOModFlowType.ConstantHead.ToString());
                }
                if (this.Drains != nModflow.Drains)
                {
                    this.Drains = nModflow.Drains;
                    props.Add(DOModFlowType.Drains.ToString());
                }
                if (this.DryCell != nModflow.DryCell)
                {
                    this.DryCell = nModflow.DryCell;
                    props.Add(DOModFlowType.DryCell.ToString());
                }
                if (this.GeneralHead != nModflow.GeneralHead)
                {
                    this.GeneralHead = nModflow.GeneralHead;
                    props.Add(DOModFlowType.GeneralHead.ToString());
                }
                if (this.HorizFlowBarrier != nModflow.HorizFlowBarrier)
                {
                    this.HorizFlowBarrier = nModflow.HorizFlowBarrier;
                    props.Add(DOModFlowType.HorizFlowBarrier.ToString());
                }
                if (this.Rivers != nModflow.Rivers)
                {
                    this.Rivers = nModflow.Rivers;
                    props.Add(DOModFlowType.Rivers.ToString());
                }
                if (this.TransientData != nModflow.TransientData)
                {
                    this.TransientData = nModflow.TransientData;
                    props.Add(DOModFlowType.TransientData.ToString());
                }
                if (this.WaterTable != nModflow.WaterTable)
                {
                    this.WaterTable = nModflow.WaterTable;
                    props.Add(DOModFlowType.WaterTable.ToString());

                }
                if (this.Wells != nModflow.Wells)
                {
                    this.Wells = nModflow.Wells;
                    props.Add(DOModFlowType.Wells.ToString());
                }


                if (props.Count > 0)
                {
                    this.AskDisplayOptionChanged(new DisplayOptionsChangedEventArgs(this, DisplayOptionsType.ModFlow, props));

                }

            }
            catch
            {


            }

            //throw new NotImplementedException();
        }

        /// <summary>
        /// 判断数据是否改变了  确定是否要通知外围该处数据变化了   不包括单独走事件的数据     
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public bool IsDataChanged( )
        {
            if (this==null )
            {
                return false;
            }
            if (this._isShowTab == false)
            {
                return false;
            }
            if (this.IsNeedUpdateData == true)
            {
                //该字段的值由界面修改该类的字段属性（不包括需要单独走事件的数据）修改则为true 否则为false
               return true;
            }
            else
            {
                return false;
            }

            //throw new NotImplementedException();
        }

        #endregion


        #region 暂时不使用



        //public void ResetDOModflow(DOModFlow nModflow)
        //{
        //    List<string> props = new List<string>();
        //    if (this._markFloodedCell != nModflow.MarkFloodedCell)
        //    {
        //        this._markFloodedCell = nModflow.MarkFloodedCell;
        //        props.Add("MarkFloodedCell");
        //    }
        //    if (this._constantHead != nModflow.ConstantHead)
        //    {
        //        this._constantHead = nModflow.ConstantHead;
        //        props.Add("ConstantHead");
        //    }
        //    if (this.Drains != nModflow.Drains)
        //    {
        //        this.Drains = nModflow.Drains;
        //        props.Add("Drains");
        //    }
        //    if (this.DryCell != nModflow.DryCell)
        //    {
        //        this.DryCell = nModflow.DryCell;
        //        props.Add("DryCell");
        //    }
        //    if (this.GeneralHead != nModflow.GeneralHead)
        //    {
        //        this.GeneralHead = nModflow.GeneralHead;
        //        props.Add("GeneralHead");
        //    }
        //    if (this.HorizFlowBarrier != nModflow.HorizFlowBarrier)
        //    {
        //        this.HorizFlowBarrier = nModflow.HorizFlowBarrier;
        //        props.Add("HorizFlowBarrier");
        //    }
        //    if (this.Rivers != nModflow.Rivers)
        //    {
        //        this.Rivers = nModflow.Rivers;
        //        props.Add("Rivers");
        //    }
        //    if (this.TransientData != nModflow.TransientData)
        //    {
        //        this.TransientData = nModflow.TransientData;
        //        props.Add("TransientData");
        //    }
        //    if (this.WaterTable != nModflow.WaterTable)
        //    {
        //        this.WaterTable = nModflow.WaterTable;
        //        props.Add("WaterTable");

        //    }
        //    if (this.Wells != nModflow.Wells)
        //    {
        //        this.Wells = nModflow.Wells;
        //        props.Add("Wells");
        //    }


        //    if (props.Count > 0)
        //    {
        //        this.AskDisplayOptionChanged(new DisplayOptionsChangedEventArgs(this, DisplayOptionsType.ModFlow, props));

        //    }
        //}

        //#region 事件模型

        //[field: NonSerialized]
        //public event EventHandler<DisplayOptionsChangedEventArgs> DisplayOptionsChanged;

        //public void AskDisplayOptionChanged(DisplayOptionsChangedEventArgs e)
        //{
        //    if (DisplayOptionsChanged != null)
        //    {
        //        DisplayOptionsChanged(this, e);

        //    }
        //}


        //#endregion

        #endregion





    }
}
